<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title></title>
	{css file="bootstrap" /}
	{css file="__TPL__/css/public.css" /}
	{js file="jquery" /}
	{css file="jqueryUI.bootstrap" /}
	{js file="jqueryUI"}
</head>
<body style="padding:10px;">
	<form action="__METH__" method="post">
	<table class="table">
		<tr>
			<th width="2%"><input type="checkbox" class="select-all input-checkbox"> </th>
			<th width="15%">菜单名称</th>
			<th>操作路径</th>
			<th>query</th>
			<th>排序</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
		{foreach from="$menus" value="$value"}
		<tr>
			<td><input type="checkbox" class="input-checkbox" m-id="{$value.id}"></td>
			<td>├─{$value.menu_name}</td>
			<td>/<?php echo trim('/'.$value['app'].'/'.$value['control'].'/'.$value['method'],'/');?>/</td>
			<td>{$value.query_string}</td>
			<td><input type="text" name="sort[{$value.id}]" value="{$value.sort}" class="input-min"></td>
			<td>{if value="$value.state"} <span class="success">显示中</span> {else /} <span class="warning">已关闭</span> {/if}</td>
			<td>
				<a href="__CONTROL__/editMenu/id/{$value.id}" class="edit-item"><i class="icon-edit"></i>修改</a>
			</td>
		</tr>
		{foreach from="$value.son_data" value="$two"}
		<tr>
			<td><input type="checkbox" class="input-checkbox" m-id="{$two.id}" /></td>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;└─{$two.menu_name}</td>
			<td>/<?php echo trim('/'.$two['app'].'/'.$two['control'].'/'.$two['method'],'/');?>/</td>
			<td>{$two.query_string}</td>
			<td><input type="text" name="sort[{$two.id}]" value="{$two.sort}" class="input-min"></td>
			<td>{if value="$two.state"} <span class="success">显示中</span> {else /} <span class="warning">已关闭</span> {/if}</td>
			<td>
				<a href="__CONTROL__/editMenu/id/{$two.id}" class="edit-item"><i class="icon-edit"></i>修改</a>
			</td>
		</tr>
		{foreach from="$two.son_data" value="$three"}
			<tr>
				<td><input type="checkbox" class="input-checkbox" m-id="{$three.id}"></td>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─{$three.menu_name}</td>
				<td>/<?php echo trim('/'.$three['app'].'/'.$three['control'].'/'.$three['method'],'/');?>/</td>
				<td>{$three.query_string}</td>
				<td><input type="text" name="sort[{$three.id}]" value="{$three.sort}" class="input-min"></td>
				<td>{if value="$three.state"} <span class="success">显示中</span> {else /} <span class="warning">已关闭</span> {/if}</td>
				<td>
					<a href="__CONTROL__/editMenu/id/{$three.id}" class="edit-item"><i class="icon-edit"></i>修改</a>
				</td>
			</tr>
			{/foreach}
		{/foreach}
		{/foreach}
		<tr class="well">
			<td><input type="checkbox" class="select-all input-checkbox"></td>
			<td colspan="3" class="opt">
				<a class="btn btn-mini btn-danger" action="del"><i class="icon-trash icon-white"></i> 删除</a>
    			<!-- <a class="btn btn-mini btn-info" action="ban"><i class="icon-ban-circle icon-white"></i> 关闭</a>
    			<a class="btn btn-mini btn-success" action="unban"><i class="icon-ok icon-white"></i> 显示</a> -->
			</td>
			<td><button type="submit" class="btn btn-mini btn-info"><i class="icon-random icon-white"></i> 排序</button></td>
			<td></td>
			<td></td>
		</tr>
	</table>
	</form>
	<div id="dialog" class="hide"></div>
	<script type="text/javascript">
		$('.select-all').click(function(){
			if($(this).attr('checked')){
				$(':checkbox["m-id"],.select-all').attr('checked',true);
			}else{
				$(':checkbox["m-id"],.select-all').attr('checked',false);
			}
		});
		$('.opt a').click(function(){
			var _checked=$('input:checked[m-id]'),
				_id=[];
			if(_checked.length==0){
				alert('请选择你需要操作的菜单!');
				return false;
			}
			_checked.each(function(k,obj){
				_id.push($(this).attr('m-id'));
			});
			if($(this).attr('action')=='del' && confirm("确认删除选中后台菜单？")){
				$.post('__CONTROL__/delMenu',{"id":_id},function(data){
					if(data==1){
						_checked.parents('tr').fadeOut(function(){
							_checked.parents('tr').remove();
						});
					}
				},'html');
			}
			return false;
		});
		$('.edit-item').click(function(){
			$.get($(this).attr('href'),function(data){
				$('#dialog').html(data);
				$('#dialog').dialog({
					"width":"500",
					"modal":true,
					"title":"修改菜单",
					"buttons":{
						"修改":function(){
							$('#dialog form').submit();
						}
					}
				});
			});
			return false;
		});
	</script>
</body>
</html>